package com.ajax;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class Searchsales
 */
@WebServlet("/Searchsales")
public class Searchsales extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Searchsales() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
			System.out.println("123");
		 //首先获得客户端发来的数据keyword
		 String id=request.getParameter("id");
		 //获得关键字后进行处理，获得关联数据
		 //List<String>listData=getData(keyword);
		 String listData = null;
		try {
			listData = getData(id);
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 //System.out.println(listData);

		response.getWriter().write(listData);
		}
	  
		public String getData(String keyword) throws ClassNotFoundException, SQLException{
			String id=keyword;
			String find="select * from sales where id='"+id+"'";
			String answer = "no";
			Jdbc j=new Jdbc();
			j.Jdbc_Q2(find);
			j.rs.first();
			String check=j.rs.getString("id");
			/*for(String data:datas){
				if(data.equals(keyword)){
					answer="yes";
				}
			}*/
			if(check!=null)
				answer="yes";
			return answer;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
